<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/plugins/layui-formSelect/formSelects-v4.css"/>
    <link rel="stylesheet"href="/css/plat-style.css">
    <style>
        thead tr th{text-align: center!important;font-weight: bold!important;}
        tr td{text-align: center!important;}
        .layui-table img {
            width: auto;
            height: auto;
            max-width: 100% !important;
            max-height: 100%;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form action="/product/industry" id="seachFrom" class="layui-form">
                    <div class="layui-card-body">
                        <%-- 查询条件设置 --%>
                        <div class="layui-container" style="padding-bottom: 50px">
                            <div class="layui-col-md12">
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm3" style="line-height: 38px">行业名称：</div>
                                    <div class="layui-col-sm7">
                                        <input type="text" name="name" class="layui-input" value="${industry.name}" placeholder="行业名称">
                                    </div>
                                </div>
                                <div class="layui-col-md5">
                                    <div class="layui-col-sm2" style="line-height: 38px">一级分类：</div>
                                    <div class="layui-col-sm8">
                                        <select class="select chosen-select" multiple data-placeholder="选择一级分类可多选"
                                                name="firstIds" xm-select="firstClassify">
                                            <c:forEach items="${firstList}" var="f">
                                                <option value="${f.id}" data-type="${f.type}" data-targetid="${f.targetId}">${f.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md3">
                                    <div class="layui-col-sm12">
                                        <button class="layui-btn layui-btn" type="submit">查询</button>
                                        <button class="layui-btn layui-btn-warm editThis" data-type="editThis"
                                                data-level="1" type="button" data-id="" data-did="">新增主行业</button>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md12" style="margin-top: 10px;margin-bottom: 10px">
                                <div class="layui-col-md4" style="line-height: 38px">
                                    <span class="green">注：深色为主行业，点击主行业可展开对应的子行业。</span>
                                </div>
                            </div>
                        </div>
                        <hr>
                        <%-- 数据展示 --%>
                        <table class="layui-table" lay-filter="industry" id="demo">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>行业名称</th>
                                <th>图片</th>
                                <th>所属分类</th>
                                <%--<th>行业范围</th>--%>
                                <th>排序</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${pageInfo.records}" var="l">
                                <tr class="parent" id="row${l.id}" style="background-color: #FAEBD7">
                                    <td width="10%">${l.id}</td>
                                    <td width="15%">${l.name}</td>
                                    <td width="10%">
                                        <img src="${l.url}" style="width: 80px;height: 40px">
                                    </td>
                                    <c:set var="f" value="${fn:split(l.classifyName, ',')}"></c:set>
                                    <td width="8%">${fn:join(f, '<br>')}</td>
                                    <%--<td width="8%">
                                        <c:if test="${l.onOff==0}">线上</c:if>
                                        <c:if test="${l.onOff==1}">线下</c:if>
                                        <c:if test="${l.onOff==2}">全部</c:if>
                                    </td>--%>
                                    <td width="8%">${l.sort}</td>
                                    <td width="8%">
                                        ${l.status==1?'<span class="layui-badge layui-bg-green">有效</span>':'<span class="layui-badge">失效</span>'}
                                    </td>
                                    <td width="20%">
                                        <button data-did="" data-id="${l.id}" data-type="editThis" data-level="2" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-normal editThis">新增子行业</button>
                                        <button data-did="" data-id="${l.id}" data-type="editThis" data-level="1" type="button"
                                                class="layui-btn layui-btn-sm layui-btn-primary editThis">编辑</button>
                                        <c:if test="${l.status==1}">
                                            <button data-id="${l.id}" data-status="0" data-level="1" data-type="updateThis" type="button"
                                                    class="layui-btn layui-btn-sm layui-btn-warm updateThis">失效</button>
                                        </c:if>
                                        <c:if test="${l.status==0}">
                                            <button data-id="${l.id}" data-status="1" data-level="1" data-type="updateThis" type="button"
                                                    class="layui-btn layui-btn-sm layui-btn-normal updateThis">生效</button>
                                        </c:if>
                                    </td>
                                </tr>
                                <c:forEach items="${l.industryDetailList}" var="d">
                                    <c:if test="${d.indId==l.id}">
                                        <tr class="child-row${l.id} child-background">
                                            <td>子行业编号： ${d.id}</td>
                                            <td>${d.name}</td>
                                            <td>
                                                <img src="${d.url}" style="width: 80px;height: 40px">
                                            </td>
                                            <td colspan="1">同上</td>
                                            <td>${d.sort}</td>
                                            <td>
                                                ${d.status==1?'<span class="layui-badge layui-bg-green">有效</span>':'<span class="layui-badge">失效</span>'}
                                            </td>
                                            <td>
                                                <button data-did="${d.id}" data-id="${l.id}" data-type="editThis" data-level="2" type="button"
                                                        class="layui-btn layui-btn-sm layui-btn-primary editThis">编辑</button>
                                                <c:if test="${d.status==1}">
                                                    <button data-id="${d.id}" data-status="0" data-level="2" data-type="updateThis" type="button"
                                                            class="layui-btn layui-btn-sm layui-btn-warm updateThis">失效</button>
                                                </c:if>
                                                <c:if test="${d.status==0}">
                                                    <button data-id="${d.id}" data-status="1" data-level="2" data-type="updateThis" type="button"
                                                            class="layui-btn layui-btn-sm layui-btn-normal updateThis">生效</button>
                                                </c:if>
                                            </td>
                                        </tr>
                                    </c:if>
                                </c:forEach>
                            </c:forEach>
                            </tbody>
                        </table>
                        <div class="test-table-reload-btn" style="margin-top: 10px;">
                            <%@include file="../paging.jsp" %>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/layui-formSelect/formSelects-v4.min.js"></script>
<script>
    //layui下拉框
    var formSelects = layui.formSelects;

    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$,
            form = layui.form,
            element = layui.element,
            layer = layui.layer;
        form.render();
        element.render();


        var active = {
            editThis: function (id,did,level) {
                layer.open({
                    title:'新增/编辑行业',
                    type: 2,
                    area: ['600px', '500px'],
                    content: '/product/industryEdit?id='+id+'&detailId='+did+'&level='+level
                });
            },
            updateThis:function (id,status,level,url) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: url,
                        data: {'id':id,'status':status,'type':level},
                        dataType: "json",
                        type: "post",
                        success: function (status) {
                            if (status) {
                                layer.msg('操作成功',{icon:1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            } else {
                                layer.msg('操作失败',{icon:2});
                            }
                        }
                    })
                });
            }
        };
        $('.editThis').on('click', function(){
            var type = 'editThis';
            //主行业id
            var id = $(this).data('id');
            //子行业id
            var did = $(this).data('did');
            //层级 1主行业；2子行业
            var level = $(this).data('level');
            active[type] && active[type].call(this,id,did,level);
        });
        $('.updateThis').on('click',function () {
            var updateThis = $(this).data('type');
            var id = $(this).data('id');
            var status = $(this).data('status');
            var level = $(this).data('level');
            var url = "/product/handleIndustryStatus";
            active[updateThis] && active[updateThis].call(this,id,status,level,url);
        });
    });

    $(function () {
        // layui下拉框多选
        formSelects.value('firstClassify');
        // 子行业tr默认隐藏
        $('tr.child-background').css({"display":"none"});
        // 点击主行业时，子行业展开
        $('tr.parent')
            .css({"cursor":"pointer"})
            .attr("title","点击这里展开/关闭")
            .click(function(){
                $(this).siblings('.child-'+this.id).toggle();
            });
    })
</script>
</body>
</html>